//
//  CoreDataHelper.swift
//  GhostWorld
//
//  Created by Kam on 2018/4/26.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit
import CoreData
import Sync

enum CoreDataEntityName: String {
  case group = "Group"
  case album = "Album"
  case audio = "Audio"
  case reader = "Reader"
  case writer = "Writer"
  case audioPlayProgress = "AudioPlayProgress"
  case playlist = "Playlist"
  case favAlbum = "FavAlbum"
  case favAudio = "FavAudio"
  case downloadingAudio = "DownloadingAudio"
  case restoreAudioList = "RestoreAudioList"
  case playHistory = "PlayHistory"
  case iapIdentifier = "IAPProduct"
  case purchaseUploadData = "PurchaseUploadData"
  case playtime = "Playtime"
  case iapPurchasedItem = "IAPPurchasedItem"
}

class CoreDataHelper {
  
  static func getContext() -> NSManagedObjectContext {
    let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
    return appDelegate.dataStack.viewContext
  }
  
  static func getDataStack() -> DataStack {
    let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
    return appDelegate.dataStack
  }
  
  //  func saveContext () {
  //    let context = CoreDataHelper.getContext()
  //    if context.hasChanges {
  //      do {
  //        try context.save()
  //      } catch let error {
  //        fatalError("Unresolved error \(error)")
  //      }
  //    }
  //  }
}
